package com.spring.until;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class JsonUtil {
    public static String getJsonString(Map map){
        JSONObject jsonObject = new JSONObject() ;
        Set set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            String key = it.next() ;
            jsonObject.put(key,map.get(key));
        }
        return jsonObject.toJSONString() ;
    }

    public static Map getMap(String jsonString){
        HashMap<String,String> map  = new HashMap<>();
        JSONObject jsonObject = JSON.parseObject(jsonString) ;
        Set set = jsonObject.keySet() ;
        Iterator<String> it = set.iterator() ;
        while (it.hasNext()){
            String key = it.next() ;
            map.put(key,jsonObject.getString(key)) ;
        }
        return map ;
    }
}
